﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using WindowsFormsApplication2.All_FORMS.Lavlah_forms;
using WindowsFormsApplication2.FORMS;
using WindowsFormsApplication2.All_FORMS.Bvrtgel_forms;
using WindowsFormsApplication2.CLASS;
using System.Collections;
using WindowsFormsApplication2.All_FORMS.Report_forms;

namespace WindowsFormsApplication2.All_FORMS.Main_forms
{
    public partial class MDIParentAdmin : Form
    {
        private SqlConnection co;
        string torol1;
        string name1,fname1,id1;
        private int childFormNumber = 0;
        ArrayList delNumbers = new ArrayList();
        public MDIParentAdmin(SqlConnection conn, string torol, string name, string fname, string id)
        {
            InitializeComponent();
            torol1 = torol;
            name1 = name;
            fname1 = fname;
            id1 = id;
            lblUser.Text = torol +":"+fname;
            co = conn;
            label3.Text = fname;
            admin();
        }

        private void admin()
        {
            if (torol1 != "")
            {
                if (torol1 == "Админ")
                {
                    //MessageBox.Show("Admin нүүр хуудас");
                    //MDIParentAdmin.ActiveForm.ParentForm.Text = name1;
                }
                if (torol1 == "Борлуулалтын Менежер")
                {
                   // MessageBox.Show("Борлуулалтын менежер нүүр хуудас");
                    btnNewAgreement.Enabled = false;

                }
                if (torol1 == "Худалдааны төлөөлөгч")
                {
                    //MessageBox.Show("Худалдааны төлөөлөгчийн нүүр хуудас");
                    ажилтанБүртгэхToolStripMenuItem.Visible = false;
                    button6.Visible = false;
                    шинээрХТБүртгэхToolStripMenuItem1.Visible = false;
                    
                    тайланToolStripMenuItem.Visible = false;
                    button6.Visible = false;
                    button5.Visible = false;
                    button3.Visible = false;
                    button1.Visible = false;
                    toolStripSeparator6.Visible = false;
                    toolStripSeparator7.Visible = false;
                    btnNewAgreement.Enabled = false;

                }
                if (torol1 == "Харилцагч")
                {
                    //MessageBox.Show("Харилцагчийн нүүр хуудас");
                    ажилтанБүртгэхToolStripMenuItem.Visible = false;
                    button4.Enabled = false;
                    бүртгэхToolStripMenuItem.Enabled = false;
                    шинээрХТБүртгэхToolStripMenuItem1.Visible = false;
              
                    тайланToolStripMenuItem.Visible = false;
                    button6.Visible = false;
                    toolStripSeparator6.Visible = false;
                    toolStripSeparator7.Visible = false;
                    btnNewAgreement.Enabled = false;
                    btnNewCar.Enabled = false;
                    btnNewUser.Enabled = false;
                    groupBox5.Visible = false;
                }
            }
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            Form childForm = new Form();
            childForm.MdiParent = this;
            childForm.Text = "Window " + childFormNumber++;
            childForm.Show();
        }

        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void шинээрЗахиалгаБүртгэхToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmOrder frm = new frmOrder(id1,co);
            frm.MdiParent = this;
            frm.Show();
        }

        private void шинээрАжилтанБүртгэхToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form frm = new frmRegWorker();
            frm.MdiParent = this;
            frm.Show();
        }

        private void шинээрХТБүртгэхToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmRegXT frm = new frmRegXT();
            frm.MdiParent = this;
            frm.Show();
        }

        private void шинээрХарилцагчБүртгэхToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmRegCustomer frm = new frmRegCustomer(co);
            frm.MdiParent = this;
            frm.Show();
        }

        private void шинээрБүтээгдэхүүнБүртгэхToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmProduct frm = new frmProduct();
            frm.MdiParent = this;
            frm.Show();
        }

        private void програмаасГарахToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void шинээрБүтээгдэхүүнБүртгэхToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmProduct frm = new frmProduct();
            frm.MdiParent = this;
            frm.Show();
        }

        private void ажилтанБүртгэхToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmRegWorker frm = new frmRegWorker();
            frm.MdiParent = this;
            frm.Show();
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmRegCustomer frm = new frmRegCustomer(co);
            frm.MdiParent = this;
            frm.Show();
        }

        private void шинээрХТБүртгэхToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmRegXT frm = new frmRegXT();
            frm.MdiParent = this;
            frm.Show();
        }

        private void шинээрЗахиалгаБүртгэхToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmOrder frm = new frmOrder(id1, co);
            frm.MdiParent = this;
            frm.Show();
        }

        private void бүтээгдэхүүнToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmProduct frm = new frmProduct();
            frm.MdiParent = this;
            frm.Show();
        }

        private void ажилтанToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmWorker frm = new frmWorker();
            frm.MdiParent = this;
            frm.Show();
        }

        private void худалдааныТөлөөлөгчToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmXT frm = new frmXT();
            frm.MdiParent = this;
            frm.Show();
        }

        private void харилцагчToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmCustomer frm = new frmCustomer(co);
            frm.MdiParent = this;
            frm.Show();  
        }

        private void сарынНэгдсэнТАЙЛАНГаргахToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string odor = "odor";
            frmTailanDate frm = new frmTailanDate(odor,fname1);
            frm.MdiParent = this;
            frm.Show();
        }

        private void хТийнТАЙЛАНГаргахToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (torol1 == "Админ")
            {
                label2.Visible = true;
                comboBox1.Visible = true;

            }
            if (torol1 == "Борлуулалтын Менежер")
            {
                label2.Visible = true;
                comboBox1.Visible = true;

            }
            if (torol1 == "Худалдааны төлөөлөгч")
            {
                frmTailanXT frm = new frmTailanXT(id1,fname1);
                frm.Show();

            }
        }

        private void бүтээгдэхүүнийТАЙЛАНГаргахToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmTailanProduct frm = new frmTailanProduct(fname1);
            frm.MdiParent = this;
            frm.Show();
        }

        private void програмынТухайToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmAbout frm = new frmAbout();
            frm.MdiParent = this;
            frm.Show();
        }

        private void MDIParentAdmin_Load(object sender, EventArgs e)
        {
            
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnNewUser_Click(object sender, EventArgs e)
        {
            frmProduct frm = new frmProduct();
            frm.MdiParent = this;
            frm.Show();
        }

        private void btnNewRequisition_Click(object sender, EventArgs e)
        {
            if (torol1 == "Админ")
            {
                frmOrder frm = new frmOrder(id1,co);
                frm.MdiParent = this;
                frm.Show();

            }
            if (torol1 == "Борлуулалтын Менежер")
            {
                frmOrder frm = new frmOrder(id1, co);
                frm.MdiParent = this;
                frm.Show();

            }
            if (torol1 == "Худалдааны төлөөлөгч")
            {   string s="";
                OrderXT frm = new OrderXT(co,id1,s);
                frm.MdiParent = this;
                frm.Show();

            }
            if (torol1 == "Харилцагч")
            {
                OrderCustomer frm = new OrderCustomer(id1, co);
                frm.MdiParent = this;
                frm.Show();

            }
        }
        

        private void btnNewAgreement_Click(object sender, EventArgs e)
        {
            if (torol1 == "Харилцагч")
            {
                frmWorker frm = new frmWorker();
                frm.MdiParent = this;
                frm.Show();
            }
            if (torol1 == "")
            {
                frmWorker frm = new frmWorker();
                frm.MdiParent = this;
                frm.Show();
            }
            if (torol1 == "Борлуулалтын Менежер")
            {
                frmWorker frm = new frmWorker();
                frm.MdiParent = this;
                frm.Show();
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            frmCustomer frm = new frmCustomer(co);
            frm.MdiParent = this;
            frm.Show(); 
        }

        private void btnNewCar_Click(object sender, EventArgs e)
        {
            
            if (torol1 == "Админ")
            {
                frmXT frm = new frmXT();
                frm.MdiParent = this;
                frm.Show();

            }
            if (torol1 == "Борлуулалтын Менежер")
            {
                frmXT frm = new frmXT();
                frm.MdiParent = this;
                frm.Show();

            }
            if (torol1 == "Худалдааны төлөөлөгч")
            {
                Form EA = new XT_Customer(id1);

                EA.ShowDialog();

            }
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string order = "zahialga";
            frmTailanDate frm = new frmTailanDate(order,fname1);
            frm.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string odor = "odor";
            frmTailanDate frm = new frmTailanDate(odor,fname1);
            frm.Show();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (torol1 == "Админ")
            {
                label2.Visible = true;
                comboBox1.Visible = true;

            }
            if (torol1 == "Борлуулалтын Менежер")
            {
                label2.Visible = true;
                comboBox1.Visible = true;

            }
            if (torol1 == "Худалдааны төлөөлөгч")
            {
                frmTailanXT frm = new frmTailanXT(id1,fname1);
                frm.Show();

            }
            
            
        }

        private void button5_Click(object sender, EventArgs e)
        {
            frmTailanProduct frm = new frmTailanProduct(fname1);
            frm.Show();
        }

        private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            frmTailanXT frm = new frmTailanXT( comboBox1.Text,fname1);
            frm.Show();
        }

        private void btnAbout_Click(object sender, EventArgs e)
        {
            frmAbout frm = new frmAbout();
            frm.Show();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            frmTugeelt frm = new frmTugeelt(fname1);
            frm.Show();
        }

      
     

    }
}
